﻿Module modGlobalData

    '数据库关联
    Public DBacs As New clsOdbcDbIf
    Public g_fDBconnect As Boolean
    Public g_iDBconnResult As Integer
    Public g_szDBIpAddress As String

    '全局变量
    Public g_szInitFileName As String
    '用户信息
    Public g_Current_UserID As String
    Public g_Current_UserName As String
    Public g_Current_WorkShop As String
    Public g_Current_Classes As String
    Public g_Current_classes_details As String

    '当前派工单信息
    Public g_Current_PGD_ID As String
    Public g_Current_PJ_Name As String
    Public g_Current_JP_Type As String
    Public g_Current_FLB_Type As String
    Public g_Current_GJB_Type As String
    Public g_Current_PROD_SPEC As String

    Public g_BHJ_LOC As String '设定保护胶画面，在【硫化前缓冲区画面】所选择库位号

    Public Enum CK_TYPE
        PW  '抛瓦后 仓库
        FLB '法兰板 仓库
        GJB '骨架板 仓库
        CPZH  '组装成品 仓库
        CPLH '硫化成品 仓库
        CP '成品 仓库
    End Enum
    Public Structure ServerDBacsTYPE
        Dim szDrive As String
        Dim szIPadr As String
        Dim szDsn As String
        Dim szDbn As String
        Dim szUid As String
        Dim szPas As String
        Dim iOver As Integer
    End Structure
    Public g_Server As ServerDBacsTYPE

    Public Const INSERT_TYPE As String = "I"
    Public Const UPDATE_TYPE As String = "U"
    Public Const DELETE_TYPE As String = "D"

    '工厂
    Public Const g_factory_id = "TS"

    '有效性
    Public Const g_validity_1 = "1" '有效
    Public Const g_validity_0 = "0" '无效

    '数据来源
    Public Const g_origin_1 = "1" 'myself
    Public Const g_origin_0 = "0" 'mes

    '喷涂车间状态
    Public Const g_pt_status_1 = "1" '创建喷涂车间mes生产计划
    Public Const g_pt_status_2 = "2" '创建喷涂车间班组生产计划
    Public Const g_pt_status_3 = "3" '喷涂车间 抛丸后 出库
    Public Const g_pt_status_4 = "4" '喷涂车间 喷砂入料
    Public Const g_pt_status_5 = "5" '喷涂车间 装配

    '车间ID
    'Public Const g_ws_pt As String = "GJB" '喷涂
    'Public Const g_ws_xj As String = "JP"   '橡胶
    Public Const g_ws_lh As String = "LH"   '硫化----硬件表专用

    '车间ID
    Public Const g_cj_pt As Integer = 1   '喷涂车间
    Public Const g_cj_xj As Integer = 2   '橡胶车间
    Public Const g_cj_lh As Integer = 3   '硫化车间
    Public Const g_cj_lxjc As Integer = 4   '力学检测车间
    Public Const g_cj_pq As Integer = 5   '喷漆车间

    '班组
    Public Const g_bz_bb As Integer = 1   '白班
    Public Const g_bz_yb As Integer = 2   '夜班
    Public Const g_bz_zb As Integer = 3   '早班
    Public Const g_bz_zhb As Integer = 4  '中班
    Public Const g_bz_wb As Integer = 5   '晚班
    Public Const g_bz_cb As Integer = 6   '常班

    '骨架板&法兰板type
    Public Const g_gjb_type_0 As Integer = 0   '骨架板
    Public Const g_flb_type_1 As Integer = 1   '法兰板

    '吊篮空满半状态
    Public Const g_dl_status_0 As String = "0"   '空
    Public Const g_dl_status_1 As String = "1"   '满
    Public Const g_dl_status_2 As String = "2"   '半

    '工段ID
    Public Const g_ws_pt_gjbps As String = "GJBPS" '骨架板喷砂
    Public Const g_ws_pt_flbps As String = "FLBPS" '法兰板喷砂
    Public Const g_ws_pt_gjbzp As String = "GJBZP" '骨架板装配
    Public Const g_ws_pt_flbzp As String = "FLBZP" '法兰板装配
    Public Const g_ws_pt_pj As String = "PJ" '喷胶

    '登录用户名
    Public g_LoginUser As String = ""

    '设备类型
    Public Const g_equipType_jxb As String = "JXB"  '机械臂
    Public Const g_equipType_yjb As String = "YJB"  '运胶臂
    Public Const g_equipType_ybb As String = "YBB"  '运板臂
    Public Const g_equipType_dzc As String = "DZC"  '电子秤
    Public Const g_equipType_smq As String = "SMQ" '读码器（喷涂车间） 
    Public Const g_equipType_Reader As String = "READER" '读码器（橡胶车间） 
    Public Const g_equipType_bhjdzc As String = "BHJDZC" '保护胶电子秤
    Public Const g_equiptype_LHJ As String = "LHJ" '硫化机
    Public Const g_equiptype_AGV As String = "AGV" 'AGV

    '保存MESSAGE
    Public htMsgMst As New Hashtable

    '主档型号
    Public Const FLBXH As String = "01" '法兰板型号
    Public Const GJBXH As String = "02" '骨架板型号
    Public Const JLXH As String = "03"  '胶料型号
    Public Const XZXH As String = "04"  '芯座型号
    Public Const WXCJ As String = "05"  '外协厂家
    Public Const MJXH As String = "06"  '模具
    Public Const KWZD As String = "07"  '库位
    Public Const BMZD As String = "08"  '部门
    Public Const LHJXH As String = "09" '硫化机型号
    Public Const QXZD As String = "10" '权限
    Public Const TPZD As String = "11" '托盘主档
    Public Const CGZD As String = "12" '仓管主档

    Public Const TM_WARNING_PW As String = "1"  '抛丸   期限管理
    Public Const TM_WARNING_PS As String = "2"  '喷砂   期限管理
    Public Const TM_WARNING_PJ As String = "3"  '喷胶   期限管理
    Public Const TM_WARNING_HLJ As String = "4" '混炼胶 期限管理
    Public Const TM_WARNING_LH As String = "5"  '待硫化 期限管理

    '胶面方向
    Public Const JMFX_UP As String = "朝上"
    Public Const JMFX_DOWN As String = "朝下"

    Public Function DBNULLtoBlank(obj As Object) As String
        Dim rtn As String = ""
        If IsDBNull(obj) Then
            rtn = ""
        Else
            rtn = obj.ToString
        End If
        Return rtn
    End Function

    Public Sub connectDB()
        'イニシャルファイル情報取得
        g_szInitFileName = My.Application.Info.DirectoryPath & "\FLB.ini"

        g_Server.szDrive = GetIniFile("SERVER", "DRIVE", "PostgreSQL ANSI", g_szInitFileName)
        g_Server.szIPadr = GetIniFile("SERVER", "IP", "", g_szInitFileName)
        g_Server.szDbn = GetIniFile("SERVER", "DBN", "ZHENANSF", g_szInitFileName)
        g_Server.szUid = GetIniFile("SERVER", "UID", "sa", g_szInitFileName)
        g_Server.szPas = GetIniFile("SERVER", "PAS", "sa", g_szInitFileName)
        g_Server.iOver = CInt(GetIniFile("SERVER", "OVER", "-1", g_szInitFileName))

        '得到当前用户名
        g_LoginUser = GetIniFile("LOGIN", "user", "admin", g_szInitFileName)

        If False = g_fDBconnect And 0 = g_iDBconnResult Then
            If "" = g_Server.szIPadr Or "0.0.0.0" = g_Server.szIPadr Then
            Else
                g_fDBconnect = True

                'データベース接続
                With g_Server
                    g_iDBconnResult = DBacs.Connect(.szDrive, .szIPadr, .szDbn, .szUid, .szPas, .iOver)
                    If 1 <> g_iDBconnResult Then
                        .szDrive = CStr(IIf("PostgreSQL" = .szDrive, "PostgreSQL ANSI", "PostgreSQL"))
                        g_iDBconnResult = DBacs.Connect(.szDrive, .szIPadr, .szDbn, .szUid, .szPas, .iOver)
                    End If
                End With
            End If
        End If

        setAllErrMsg()
    End Sub
    Public Sub setAllErrMsg()
        'メッセージが取得済みの場合は設定しない
        If htMsgMst.Count = 0 Then
            Dim objmsg As New clsMessage
            Dim dtMsgMst As DataTable = objmsg.GetAllMsg()
            For Each dr In dtMsgMst.Rows
                With htMsgMst
                    .Add(dr("msg_id"), dr("msg"))
                End With
            Next
        End If
    End Sub
    Public Function getMsgStr(ByVal msgId As String, Optional ByVal args1 As String = "", Optional ByVal args2 As String = "", Optional ByVal args3 As String = "") As String

        If String.IsNullOrEmpty(args1) AndAlso String.IsNullOrEmpty(args2) AndAlso String.IsNullOrEmpty(args3) Then
            getMsgStr = htMsgMst(msgId)
            Exit Function

        ElseIf Not String.IsNullOrEmpty(args1) AndAlso Not String.IsNullOrEmpty(args2) AndAlso String.IsNullOrEmpty(args3) Then
            getMsgStr = String.Format(htMsgMst(msgId), args1, args2)
            Exit Function
        ElseIf Not String.IsNullOrEmpty(args1) AndAlso Not String.IsNullOrEmpty(args2) AndAlso Not String.IsNullOrEmpty(args3) Then
            getMsgStr = String.Format(htMsgMst(msgId), args1, args2, args3)
            Exit Function
        Else
            getMsgStr = String.Format(htMsgMst(msgId), args1, args2)
            Exit Function
        End If

    End Function
End Module
